package edu.ccut.saturn.component;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
 * 定时器构件的执行任务类，每执行一次任务都会调用这个类
 * 
 * @author 李佳伦
 * 
 * @version 1.0 2009.6.12
 * 
 * @see SaturnTask
 */
public class SaturnTaskJob implements Job {
	
	private static final String LOGGER_KEY_COMPONENT_RUNTIME = SaturnLoggerManager.LOGGER_KEY_COMPONENT_RUNTIME;

	protected static ILogger logger = SaturnLoggerManager.getInstance().getSaturnLogger(LOGGER_KEY_COMPONENT_RUNTIME);

	private static final String PARAMETER_CONTEXT = "parameterContext";

	private static final String LOGIC_FULLKEY = "logicfullkey";

	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

		String logicFullkey = jobExecutionContext.getMergedJobDataMap().getString(LOGIC_FULLKEY);
		
		IParameterContext parameterContext = (IParameterContext) jobExecutionContext.getMergedJobDataMap().get(PARAMETER_CONTEXT);
		IComponent component = null;
		
			try {
				component = ComponentManager.getInstance().getComponent(logicFullkey);
				if (component != null) {
					component.execute(parameterContext);
				}
			} catch (SaturnComponentException e) {
				logger.debug("can noe execute task ! taskfullkey is " + logicFullkey, e);
			} catch (Exception e) {
				logger.debug("can noe execute task ! taskfullkey is " + logicFullkey, e);
			}
		
	}
}
